# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
# Contributor: Jurica Bradarić <jbradaric@gmail.com>
# Contributor: jprjr <john@jrjrtech.com>

pkgname=('libluv' 'lua-luv' 'lua51-luv' 'lua52-luv' 'lua53-luv')
pkgbase=libluv
pkgver=1.45.0_0
pkgrel=1
pkgdesc='Bare libuv bindings for lua'
arch=('loong64' 'x86_64')
url='https://github.com/luvit/luv'
license=('APACHE')
depends=('libuv')
makedepends=('cmake' 'libuv' 'ninja' 'luajit' 'lua>=5.4.0' 'lua<5.5.0' 'lua51' 'lua52' 'lua53')
source=("https://github.com/luvit/luv/releases/download/${pkgver//_/-}/luv-${pkgver//_/-}.tar.gz")
sha256sums=('fa6c46fb09f88320afa7f88017efd7b0d2b3a0158c5ba5b6851340b0332a2b81')

build() {
  # build per-lua versions
  for ver in 5.1 5.2 5.3 5.4; do
    incdir="/usr/include/lua${ver}"
    if [ "$ver" = "5.4" ] ; then
      incdir="/usr/include"
    fi
    cmake -GNinja \
      -Bbuild-lua${ver//./} \
      -DLUA=/usr/bin/lua${ver} \
      -DLUA_INCDIR=${incdir} \
      -DLUADIR=/usr/share/lua/${ver} \
      -DLIBDIR=/usr/lib/lua/${ver} \
      -DWITH_SHARED_LIBUV=ON \
      -DLUA_BUILD_TYPE=System \
      -DCMAKE_INSTALL_PREFIX=/usr \
      "luv-${pkgver//_/-}"
    ninja -C "build-lua${ver//./}"
  done

  # build shared library version
  cmake -GNinja \
    -Bbuild \
    -DWITH_SHARED_LIBUV=ON \
    -DLUA_BUILD_TYPE=System \
    -DBUILD_MODULE=OFF \
    -DBUILD_SHARED_LIBS=ON \
    -DCMAKE_INSTALL_PREFIX=/usr \
    "luv-${pkgver//_/-}"
  ninja -C "build"
}

package_libluv() {
  depends+=('luajit')
  DESTDIR="${pkgdir}" ninja -C "build" install
}

package_lua-luv() {
  pkgdesc+=' - Lua module'
  depends+=('lua')
  DESTDIR="${pkgdir}" ninja -C "build-lua54" install
}

package_lua51-luv() {
  pkgdesc+=' - Lua 5.1 module'
  depends+=('lua51')
  DESTDIR="${pkgdir}" ninja -C "build-lua51" install
}

package_lua52-luv() {
  pkgdesc+=' - Lua 5.2 module'
  depends+=('lua52')
  DESTDIR="${pkgdir}" ninja -C "build-lua52" install
}

package_lua53-luv() {
  pkgdesc+=' - Lua 5.3 module'
  depends+=('lua53')
  DESTDIR="${pkgdir}" ninja -C "build-lua53" install
}

# vim:set ts=2 sw=2 et:
